﻿namespace MVVMBasedDialogs
{
    using System.Windows;
    using GalaSoft.MvvmLight;

    public interface IDialogService
    {
        MessageBoxResult ShowMessageBox(string content, 
            string title, MessageBoxButton buttons);

        void ShowDialog(ViewModelBase viewModel);
    }
    
    public class DialogService : IDialogService
    {
        static IDialogService _instance;
        public static IDialogService Instance
        {
            get 
            {
                if (_instance == null)
                {
                    _instance = new DialogService();
                }
                return _instance;
            }
        }

        public MessageBoxResult ShowMessageBox(string content, 
            string title, MessageBoxButton buttons)
        {            
            return MessageBox.Show(content, title, buttons);            
        }

        public void ShowDialog(ViewModelBase viewModel)
        {
            var dialog = new DialogView() { DataContext = viewModel };
            dialog.Owner = Application.Current.MainWindow;
            dialog.ShowInTaskbar = false;
            dialog.ShowDialog();
        }
    }
}
